package com.dhy.takeaway.service;

import com.dhy.takeaway.dao.FrontLoginDao;
import com.dhy.takeaway.entity.Buyer;
import com.dhy.takeaway.entity.Res;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class FrontLoginService {
    @Autowired
    FrontLoginDao frontLoginDao;

    public Res findBuyer(Buyer buyer){
        Res res = new Res();
        if (frontLoginDao.findBuyer(buyer) != null) {
            res.setCode("200");
            res.setMessage("验证成功！");
        } else {
            res.setCode("400");
            res.setMessage("验证失败！");
        }

        return res;
    }

    public Res register(Buyer buyer){
        Res res = new Res();
        buyer.setCreateTime(new Date());
        buyer.setUpdateTime(new Date());
        if (frontLoginDao.insertBuyer(buyer) > 0) {
            res.setCode("200");
            res.setMessage("注册成功！");
        } else {
            res.setCode("400");
            res.setMessage("注册失败！");
        }

        return res;
    }

}
